package weekMatch.two_103;

import javafx.scene.effect.SepiaTone;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class LeeCode_02 {
    public static void main(String[] args) {
        System.out.println(Arrays.toString(findThePrefixCommonArray(new int[]{1, 3, 2, 4}, new int[]{3, 1, 2, 4})));
    }
    private static int[] findThePrefixCommonArray(int[] A, int[] B) {
        Set<Integer> sa = new HashSet<>();
        Set<Integer> sb = new HashSet<>();
        int n = A.length;
        int[] ans = new int[n];
        for (int i = 0; i < n; i++) {
            sa.add(A[i]);
            sb.add(B[i]);
            if (i == 0){
                ans[i] = A[0] == B[0] ? 1 : 0;
            }else {
                int son = 0;
                for (int j = 0; j <= i; j++) {
                    if (sa.contains(B[j])){
                        son++;
                    }
                }
                ans[i] = son;
            }
        }
        return ans;
    }
}
